﻿namespace DotRas
{
    using DotRas.Design;
    using pptpclient.Properties;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Design;
    using System.Runtime.InteropServices;
    using System.Security;
    using System.Security.Permissions;

    [ToolboxItem(true), ToolboxBitmap(typeof(RasDialDialog), "DotRas.RasDialDialog.bmp")]
    public sealed class RasDialDialog : RasCommonDialog
    {
        private string _entryName;
        private string _phoneBookPath;
        private string _phoneNumber;
        private int _subEntryId;

        public override void Reset()
        {
            this.PhoneBookPath = null;
            this.EntryName = null;
            this.PhoneNumber = null;
            this.SubEntryId = 0;
            base.Reset();
        }

        [UIPermission(SecurityAction.Demand, Window=UIPermissionWindow.SafeSubWindows)]
        protected override bool RunDialog(IntPtr hwndOwner)
        {
            DotRas.NativeMethods.RASDIALDLG lpInfo = new DotRas.NativeMethods.RASDIALDLG {
                size = Marshal.SizeOf(typeof(DotRas.NativeMethods.RASDIALDLG)),
                hwndOwner = hwndOwner,
                subEntryId = this.SubEntryId
            };
            if (base.Location != Point.Empty)
            {
                lpInfo.left = base.Location.X;
                lpInfo.top = base.Location.Y;
                lpInfo.flags |= DotRas.NativeMethods.RASDDFLAG.PositionDlg;
            }
            bool flag = false;
            try
            {
                flag = DotRas.UnsafeNativeMethods.RasDialDlg(this.PhoneBookPath, this.EntryName, this.PhoneNumber, ref lpInfo);
                if (!flag && (lpInfo.error != 0))
                {
                    RasErrorEventArgs e = new RasErrorEventArgs(lpInfo.error, RasHelper.GetRasErrorString(lpInfo.error));
                    base.OnError(e);
                }
            }
            catch (EntryPointNotFoundException)
            {
                DotRas.ThrowHelper.ThrowNotSupportedException(Resources.Exception_NotSupportedOnPlatform);
            }
            catch (SecurityException)
            {
                DotRas.ThrowHelper.ThrowUnauthorizedAccessException(Resources.Exception_AccessDeniedBySecurity);
            }
            return flag;
        }

        [DotRas.SRCategory("CatData"), DotRas.SRDescription("REDEntryNameDesc"), DefaultValue((string) null)]
        public string EntryName
        {
            get
            {
                return this._entryName;
            }
            set
            {
                this._entryName = value;
            }
        }

        [DotRas.SRCategory("CatData"), Editor(typeof(PhoneBookFileNameEditor), typeof(UITypeEditor)), DefaultValue((string) null), DotRas.SRDescription("RDPhoneBookPathDesc")]
        public string PhoneBookPath
        {
            get
            {
                return this._phoneBookPath;
            }
            set
            {
                this._phoneBookPath = value;
            }
        }

        [DotRas.SRDescription("RDDPhoneNumberDesc"), DefaultValue((string) null), DotRas.SRCategory("CatData")]
        public string PhoneNumber
        {
            get
            {
                return this._phoneNumber;
            }
            set
            {
                this._phoneNumber = value;
            }
        }

        [DotRas.SRDescription("RDSubEntryIdDesc"), DotRas.SRCategory("CatData"), DefaultValue(0)]
        public int SubEntryId
        {
            get
            {
                return this._subEntryId;
            }
            set
            {
                this._subEntryId = value;
            }
        }
    }
}

